package com.afinal.intelligencetrash.ui.MapUtils;

import android.content.Context;
import android.content.res.Resources;
import android.support.v7.widget.AppCompatTextView;
import android.view.LayoutInflater;
import android.view.View;

import com.afinal.intelligencetrash.R;
import com.amap.api.maps.AMap;
import com.amap.api.maps.model.Marker;

/**
 * Created by cyy on 17-10-13.
 */

public class MarkerInfoWindowAdapter implements AMap.InfoWindowAdapter {
    private Context mContext;

    public MarkerInfoWindowAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public View getInfoWindow(final Marker marker) {
        MarkerDo markerDo = (MarkerDo) marker.getObject();
        View rootView = LayoutInflater.from(mContext).inflate(R.layout.marker_info_window, null);
        AppCompatTextView capacity_value = (AppCompatTextView) rootView.findViewById(R.id.capacity_value);
        AppCompatTextView temperature_value = (AppCompatTextView) rootView.findViewById(R.id.temperature_value);
        AppCompatTextView humidness_value = (AppCompatTextView) rootView.findViewById(R.id.humidness_value);
        AppCompatTextView semll_value = (AppCompatTextView) rootView.findViewById(R.id.semll_value);
        AppCompatTextView address_value = (AppCompatTextView) rootView.findViewById(R.id.address_value);
        AppCompatTextView goToHere = (AppCompatTextView) rootView.findViewById(R.id.goToHere);
        Resources res =  mContext.getResources();
        capacity_value.setText(String.format(res.getString(R.string.capacity_value), markerDo.getTrashStatusDo().getContent()));
        temperature_value.setText(String.format(res.getString(R.string.temperature_value), markerDo.getTrashStatusDo().getSidu()));
        humidness_value.setText(String.format(res.getString(R.string.humidness_value), markerDo.getTrashStatusDo().getWendu()));
        address_value.setText(markerDo.getAddress());

        if(markerDo.getTrashStatusDo().getSmell() == 0){
            semll_value.setText(res.getString(R.string.semll_value_nomal));
        }else {
            semll_value.setText(res.getString(R.string.semll_value_peculiar));
        }

        goToHere.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(goToHereOnClickLister != null){
                    goToHereOnClickLister.onClick(v, marker);
                }
            }
        });
        return rootView;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    private GoToHereOnClickLister goToHereOnClickLister;

    public static interface GoToHereOnClickLister{
        void onClick(View v, Marker marker);
    }

    public void setGoToHereOnClickLister(GoToHereOnClickLister listener){
        this.goToHereOnClickLister = listener;
    }
}
